# -*- coding:utf-8 -*-
__author__ = 'CYY'
from http_to_wechat import exec_http, mutiple_exec_http, direct_exec_http
from time_convert_util import timestamp2date, calu
from dao import exec_sql
from constant_util import logger


def err_msg_format(err_msg):
    status_enum = {
        '60': 'KILLED',
        '70': 'FAILED',
        '125': 'CANCELLED'
    }
    return """
    azkanban目前错误的job信息：
    Execution '""" + str(err_msg.get('exec_id')) + """' of flow '""" + err_msg.get(
        'flow_id') + """' of project '""" + err_msg.get('name') + """' has failed on BIG-DATA
    Start Time\t\t""" + timestamp2date(err_msg.get('start_time')) + """
    End Time\t\t""" + timestamp2date(err_msg.get('end_time')) + """
    Duration\t\t""" + calu(err_msg.get('end_time'), err_msg.get('start_time')) + """ sec
    Status\t\t""" + status_enum[str(err_msg.get('status'))] + """
    """


def exec_check():
    for exec_result in exec_sql():
        # mutiple_exec_http(err_msg_format(exec_result))
        direct_exec_http(exec_result.get('name'), err_msg_format(exec_result))


if __name__ == '__main__':
    exec_check()
    logger.info("executing")
